Tuesday, September 28, 2004

Just-In-Time compiler

The CLR never executes Common Intermediate Language (CIL) directly. Instead, the Just-In-Time (JIT) compiler translates CIL into optimized x86 native instructions. That’s why using managed code lets your software run in different environments safely and efficiently. In addition, using machine language lets you take full advantage of the features of the processor the application is running on. For example, when the JIT encounters an Intel processor, the code produced takes advantage of hyper-threading technology.

Another advantage of the JIT is improved performance. The JIT learns when the code does multiple iterations. The runtime is designed to be able to retune the JIT compiled code as your program runs.

Versioning essentially eliminates “DLL hell.” When you define an assembly as strongly named, the .NET executable will be executed with the same DLL with which it was built. This means that you can have side-by-side versions of a DLL, However, when an application calls unmanaged DLLs, you can end up back in “DLL hell.”


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

ODBC.NET Data Provider

The ODBC.NET Data Provider is a native component to the .NET Framework version 1.1. This component provides access to native ODBC drivers in the same way that the OLE DB .NET Data Provider provides access to native OLE DB providers.The ODBC.NET Data Provider is intended to work with all compliant ODBC drivers like eg.

* Microsoft SQL ODBC Driver
* Microsoft ODBC Driver for Oracle
* Microsoft Jet ODBC Driver

Unlike the ODBC .NET data provider addon for .NET Framework 1.0, the namespace for this version changed from Microsoft.Data.Odbc to System.Data.Odbc. The Connection strings will be as follows for different data sources.

The connection string for a SQL Server database looks like following:
DRIVER={SQL Server};SERVER=TigerServer;UID=sa;PWD=;DATABASE=northwind;

The connection string for an Oracle database looks like following:
Driver={Microsoft ODBC for Oracle};Server=ORACLE8i;UID=User1;PWD=xxxx

The connection string for a Microsoft Access database looks like following:
Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\Northwind.mdb

The connection string for an Excel database looks like following:
Driver={Microsoft Excel Driver (*.xls)};DBQ=C:\ExcelFile1.xls

The connection string for a text database looks like following:
Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=C:\TextFile1.txt


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

How can I write a secure class? How to apply security to a class?

You can change the DACL on the registry hive you want to allow access to.
There are lots of aspects to security but at a minimum are listed below:

* never trust input data: validate it and/or encode it before using it or echo'ing it back
* be very careful about constructing SQL queries in text using user input. Prefer paramterized stored procedures if you can use them.
* Validate arguments to p/invoke calls and minimize the use of "unsafe" code in C#

There is a white paper http://msdn.microsoft.com/library/defaultasp?url=/library/en-us/dnbda/html/authaspdotnet.asp with more recommendations and considerations.


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Callback functions

Callback functions are powerful tools and we should know how to use them...
In general a callback function is a reference to a method that you pass to
another method... When the second method calls the referenced method , it
actually calls back to the first method... This might be a confusing
terminology but a code snippet from MSDN will probably help make it
clearer...

using System;
using System.Runtime.InteropServices;

public delegate bool CallBack(int hwnd, int lParam);

public class EnumReportApp {

[DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);

public static void Main()
{
CallBack myCallBack = new CallBack(EnumReportApp.Report);
EnumWindows(myCallBack, 0);
}

public static bool Report(int hwnd, int lParam) {
Console.Write("Window handle is ");
Console.WriteLine(hwnd);
return true;
}
}

Here is the link for you to explore more....
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconusingcallbackfunctions.asp


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Set Option Strict for all VB Projects

Although VB.NET allows you to perform implicit type conversions and late binding, you should avoid these practices. Implicit type conversions and late binding may lead to severe performance problems, runtime errors, and code that is difficult to read and maintain. For optimal performance, you should instruct Visual Basic to disallow implicit type conversions and late binding for all Visual Basic files. You should turn Option Strict on for all files in your project.


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

In VB.NET, use DirectCast instead of CType

Visual Basic .NET provides two options for casting. CType casts or converts one type into another type. If the types do not match, coercion may be performed. DirectCast casts one type to another type but does not perform corecion if the types do not match. The main difference between the two is that DirectCast is only works if the specified type and the run-time type of the expression are the same.


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Quick MultiThreading

This is some real quick good info for specific scenarios... If you
are writing some workflow logic of yours and in-between you realize that you
want to perform some tasks which would be time consuming but actually are
also apart from your actual business logic and so you would not want your
business logic to waste on performance by waiting for those tasks to
complete... Some of the examples of such tasks would be printing, cleaning
back-end, doing logging or tracing functionality etc...
Well this is when the System.Threading.ThreadPool class comes real
handy... There is a static method called QueueUserWorkItem... You can call
this method with the method that you want to execute Asynchronously... The
Threadpool will use the first available thread to process your request...
Now your main business logic does not need to wait for this function to
finish...
Now this function can as well give a call back but then it depends
upon your requirements...
Read more about it on MSDN...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemthreadingthreadpoolclasstopic.asp




With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Common questions asked in VB technical interview

1.What versions of VB have you used? Have you used VBA or VBScript?
2.Have you ever created ActiveX controls? If so, what did they do?
3.Have you ever created ActiveX DLLs? If so, why did you create the
DLLs instead of using code in the main application?
4.Have you ever created ActiveX EXEs? If so, what were they used for?
5.What third party ActiveX controls have you used?
6.Have you ever used ADO? How about any other database engines?
7.Have you ever used classes? If so, how have you used them?
8.Have you ever used Collections? Collection Classes?
9.Have you ever used resource files? If so, for what reason?
10.Have you used the Dictionary Object?
11.Have you used the FileSystemObject?
12.What database backends have you worked with? Access? SQL Server? Oracle?
13.What version control systems have you used?
14.What versions of Windows have you used? Have you used any other
operating systems?
15.Have you developed components for MTS? How about IIS and/or ASP
pages? Any other server based components?
16.Are there any other programming tools, such as database diagramming
or CASE tools, that you've used?
17.Have you ever created Web Classes? ActiveX documents? Any other web
based components?
18.Have you ever built a DCOM application?


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Resource File Generator Tool

Resource file generator tool is used to convert resource file in the form of
.txt or .resx files to common language runtime binary .resources files...
These files can be compiled into satellite assemblies..

This utility can do conversions in other directions too and uses following
classes to do the conversions
ResourceReader Class
ResourceWriter Class
ResXResourceReader Class
ResXResourceWriter Class

The exe name for the tool is ResGen.exe... If you search MSDN with the
keyword you will find ample information...



With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/